<template>
  <div class="app-container">

    <div class="filter-container">
      <!-- <el-select
        v-model="listQuery.error_type"
        style="width: 150px"
        class="filter-item"
        @change="handleFilter"
      >
         <el-option label="全部状态" :value="''" />
        <el-option v-for="(v, k) in error_type" :key="k" :label="v" :value="k" />
        
      </el-select> -->
      <el-select
          v-model="listQuery.query_type"
          style="width: 150px"
          class="filter-item"
          @change="handleFilter"
        >
          <el-option label="实时" :value="'1'" />
          <el-option label="历史" :value="''" />
        </el-select>

        <el-select
          v-model="listQuery.pkg"
          style="width: 150px"
          class="filter-item"
          @change="handleFilter"
        >
           <el-option label="全部包" :value="''" />
          <el-option v-for="(v, k) in pkgs" :key="k" :label="v" :value="k" />
          
        </el-select>
        <el-select
            v-model="listQuery.brand"
            clearable
            filterable
            style="width: 150px"
            class="filter-item"
            @change="handleFilter"
            placeholder="厂商"
          >
          <el-option key="100" label="所有厂商" value=""></el-option>
          <el-option
            v-for="(v, k, index) in brand1"
            :key="index"
            :label="v"
            :value="k"
          />
        </el-select>
      <el-button
       plain size="small"
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >搜索</el-button>

      <el-button
       plain size="small"
        v-waves
        class="filter-item btn"
        type="primary"
        icon="el-icon-refresh"
        @click="handleCancel"
      >重置</el-button>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-table
              :data="props.row.sum_content"
              border
              style="width: 100%">
              <el-table-column prop="version" label="版本" align="center"> </el-table-column>
              <el-table-column prop="number" align="center" label="数量"> </el-table-column>
              <el-table-column label="占比" min-width="" align="center">
                <template slot-scope="{row}">
                  <span>{{ (row.number / props.row.sum * 100).toFixed(2) }}%</span> 
                </template>
              </el-table-column>
              
            </el-table>
          </el-form>

        </template>
      </el-table-column>
      
      <el-table-column label="包" min-width="" align="center">
        <template slot-scope="{row}">
          <span>{{ pkgs[row.pkg] }}</span> 
        </template>
      </el-table-column>
      <el-table-column label="厂商" min-width="" align="center">
        <template slot-scope="{row}">
          <span>{{ row.brand }}</span> 
        </template>
      </el-table-column>
      <el-table-column label="数量" prop="sum" align="center"> </el-table-column>
      <el-table-column label="时间" min-width="100" align="center">
        <template slot-scope="{row}">
          <span>{{ row.create_time }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      class="pageShow"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  getAndroidV,
  getPkgList
} from "@/api/adv_admin/config";
// import {
//   quickLogin,
// } from "@/api/admin/control";addProxyOrqudao
import waves from "@/directive/waves"; // waves directive
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import {brand1} from '@/utils/index'
export default {
  name: "Control",
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      brand1,
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        pkg: "",
        brand: "",
        query_type: '1'
      },
      error_type: {},
      pkgs:{}
    };
  },
  created() {
    this.getPkgs();
    this.getList();
  //   this.setDialogWidth();
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        this.setDialogWidth();
      })();
    };
  },
  methods: {
    getPkgs(){
      getPkgList().then((res)=>{
          this.pkgs = res.DATA.list
        })
      },
    setDialogWidth() {
      const val = document.body.clientWidth;
      const def = 600; // 默认宽度
      if (val < def) {
        this.dialogWidth = "100%";
      } else {
        this.dialogWidth = def + "px";
      }
    },
    getList() {
      this.listLoading = true;
      getAndroidV(this.listQuery).then((response) => {
        this.list = response.DATA.list;
        this.total = response.DATA.total;
        this.listLoading = false;
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleCancel(){
      this.listQuery = {
        page: 1,
        limit: 20,
        pkg: "",
        brand: "",
        query_type: '1'
      }
      this.getList()
    }
  
  },
};
</script>

<style lang="scss" scoped>
.show-pwd {
  position: absolute;
  right: 10px;
  top: 0;
  font-size: 16px;
  color: #ccc;
  cursor: pointer;
  user-select: none;
}
.push {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  margin-left: 5px;
}
.pageHidden {
  display: none;
}
.btn {
  margin-left: 0;
}
.fullwidth {
  width: 450px;
  margin-left: 50px;
}
@media (max-width: 550px) {
  .pageShow {
    display: none;
  }
  .pageHidden {
    display: block;
  }
  .fullwidth {
    width: 100%;
    margin-left: 0;
  }
}
</style>
